<?php
/**
*
* If the "cntr_id" parameter is -1, it's a new record.
* Otherwise, we're updating an old record.

*/
if (!isset($gCms)) exit;

// get our records from the database
$db = $gCms->GetDb();


if (isset($params['cntr_id']) && $params['cntr_id'] != -1)
{
	// we received a cntr_id that was not -1, which means we're updating an
	// existing record. So we issue a SQL Update
   $query = 'UPDATE '.cms_db_prefix().
      'module_counters set value=? where cntr_id = ?';
   $result = $db->Execute($query, array(0, $params['cntr_id']));
   $params['module_message'] = $this->Lang('updated_record');
}
else
{
   // error????
   return;
}

if ($result === false)
{
   // yeah, that's graceful :(
   echo "Database error!";
   exit;
}

unset($params['cntr_id']);
// set a message and return to the page.
#$this->Redirect($id, 'default', $returnid, $params);
$this->Redirect($id, "defaultadmin",$returnid , array('msg'=>'message_success', 'tab'=>'counters'));
#$this->Redirect($id, "defaultadmin", '', array('msg'=>'message_success', 'tab'=>'counters'));
#$this->Redirect($id, 'defaultadmin', $returnid, $parms);

?>